package stu.kurs.services.impl;

import javax.ejb.EJB;
import javax.ejb.Stateful;
import stu.kurs.domain.User;
import stu.kurs.exceptions.ServiceException;
import stu.kurs.services.IAuthorizationService;
import stu.kurs.services.IUserService;

@Stateful(name="AuthorizationService")
public class AuthorizationService implements IAuthorizationService {
	
	@EJB(beanName="UserService")
	private IUserService userService;

	public Integer login(String email, String password) throws ServiceException {
		System.err.println("---------------------AutorizationService---------------------");
		User u = userService.findByEmail(email);
		if (u == null) return null;
		if (userService.getMD5(password).equals(u.getPassword())){
			return u.getLevel();
		}
		else return null;
	}
}